import os
import time

# Write lines to save path.
def save_lines(config, lines: list, word_sep='', sentence_sep='\n'):
    line_len = '_' + str(len(lines)) + '行'

    save_path = config.get('save_path', '')
    if not save_path:
        save_path = os.path.join(config.get('base', ''), r'data/save/result.txt')

    save_dir = os.path.dirname(save_path)
    if not save_dir:
        os.makedirs(save_path)
    
    file_pre = os.path.splitext(save_path)[0]
    file_end = os.path.splitext(save_path)[1]

    cur_time = time.strftime('_%Y年_%m月_%d日%H时%M分%S秒',time.localtime(time.time()))
    save_path = file_pre + cur_time + file_end + line_len

    with open(save_path, 'w', encoding='utf-8') as fw:
        for line in lines:
            if word_sep:
                line = ''.join(line)
            fw.write(line + sentence_sep)
    